package com.xgpro.pc.studycentre.controller;

import com.xgpro.common.controller.BaseController;
import com.xgpro.common.exceptions.BusinessRuntimeException;
import com.xgpro.common.results.ResponseResult;
import com.xgpro.domain.studycentre.vo.InnerTea;
import com.xgpro.domain.studycentre.vo.OutTea;
import com.xgpro.domain.studycentre.vo.TeaFront;
import com.xgpro.domain.studycentre.vo.TeaPCFront;
import com.xgpro.pc.studycentre.service.TeaPCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author tx
 * @version 1.0
 * @date 2019/10/15 22:44
 */
@RestController
@RequestMapping("/teaPC")
@CrossOrigin(allowCredentials="true")
public class TeaPCController extends BaseController {
    @Autowired
    private TeaPCService teaPCService;

    /**
     * 查询导师信息
     * @param teaFront
     * @return
     */
    @RequestMapping("/qryTeaPCResult")
    public ResponseResult qryTeaPCResult(@RequestBody TeaPCFront teaFront){
           return ResponseResult.ok(teaPCService.qryTeaPCResult(teaFront));
    }

    /**
     * 新增内部导师
     * @param innerTea
     * @return
     */
    @RequestMapping("/insertInnerTea")
    public ResponseResult insertInnerTea(@RequestBody InnerTea innerTea){
            try{
                return ResponseResult.ok(teaPCService.insertInnerTea(innerTea));
            }catch (BusinessRuntimeException e){
                //e.printStackTrace();
                return ResponseResult.failure(e.getErrorCode(),e.getMessage());
            }

    }

    /**
     * 新增外部导师
     * @param outTea
     * @return
     */
    @RequestMapping("/insertOutTea")
    public ResponseResult insertOutTea(@RequestBody OutTea outTea){
        return ResponseResult.ok(teaPCService.insertOutTea(outTea));
    }


    /**
     * 删除导师
     * @param id
     * @return
     */
    @RequestMapping("/deleteTeaById")
    public ResponseResult deleteTeaById(Integer id){
        return ResponseResult.ok(teaPCService.deleteTeaById(id));
    }

    /**
     * 批量删除导师
     * @param ids
     * @return
     */
    @RequestMapping("/deleteTeaByIds")
    public ResponseResult deleteTeaByIds(@RequestBody List<Integer> ids){
        return ResponseResult.ok(teaPCService.deleteTeaByIds(ids));
    }

    /**
     * 修改内部导师信息
     * @param innerTea
     * @return
     */
    @RequestMapping("/updateInnerTea")
    public ResponseResult updateInnerTea(@RequestBody InnerTea innerTea){
        return ResponseResult.ok(teaPCService.updateInnerTea(innerTea));
    }


    /**
     * 修改外部导师信息
     * @param outTea
     * @return
     */
    @RequestMapping("/updateOutTea")
    public ResponseResult updateOutTea(@RequestBody OutTea outTea){
        return ResponseResult.ok(teaPCService.updateOutTea(outTea));
    }

    /**
     * 外部导师搜索
     * @param teaName
     * @return
     */
    @RequestMapping("/qryTeaBySelect")
    public ResponseResult qryTeaBySelect(String teaName){
        return ResponseResult.ok(teaPCService.qryTeaBySelect(teaName));
    }

    /**
     * 搜索所有用户
     * @param userName
     * @return
     */
    @RequestMapping("/qryUserBySelect")
    public ResponseResult qryUserBySelect(String userName){
        return ResponseResult.ok(teaPCService.qryUserBySelect(userName));
    }

    /**
     * 导入内部导师
     * @param multipartFile
     * @return
     */
    @RequestMapping("/importTea")
    public ResponseResult importTea(MultipartFile multipartFile){
        try{
            return ResponseResult.ok(teaPCService.importTea(multipartFile));
        }catch (BusinessRuntimeException e){
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

}
